package com.netbao.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result {
    private boolean flag;//是否成功
    private Integer code;// 返回码
    private String message;//返回信息
    private Object data;// 返回数据

    public static Result ok(Integer code, String message, Object data){
        return new Result(true,code,message,data);
    }

    public static Result ok(String message, Object data){
        return ok(StatusCode.OK,message,data);
    }

    public static Result ok(Object data){
        return ok(StatusCode.OK,"操作成功",data);
    }

    public static Result ok(String message){
        return ok(StatusCode.OK,message,null);
    }

    public static Result ok(){
        return ok("操作成功");
    }

    public static Result error(Integer code, String message, Object data){
        return new Result(false,code,message,data);
    }

    public static Result error(String message, Object data){
        return error(StatusCode.ERROR,message,data);
    }

    public static Result error(String message){
        return error(StatusCode.ERROR,message,null);
    }

    public static Result error(Object data){
        return error(StatusCode.ERROR,"操作失败",data);
    }

    public static Result error(){
        return error("操作失败");
    }
}
